import book.BookList;
import users.AdminUser;
import users.NormalUser;
import users.User;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA
 * Description:主系统
 * User:22954
 * Date:2024-01-12
 * Time:20:31
 */
public class Main {
    public static User login() {
        System.out.println("Welcome to the library system!");
//        System.out.print("请输入用户名:");
        System.out.print("Please enter your username:");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        while (true) {
//          System.out.println("请输入登录方式: 1.用户  0.管理员");
            System.out.println("Please enter the login identity:  1.User   0.Administrator");
            int choice = scanner.nextInt();
            if (choice == 1) {
                return new NormalUser(name);
            } else if (choice == 0) {
                return new AdminUser(name);
            } else {
                System.out.println("Typing error! Please try again.");
            }
        }
    }

    public static void main(String[] args) {
        //1.创建图书馆
        BookList bookList = new BookList();
        //2.加载
        User user = login();
        while (true) {
            int choice = user.menu();
//          System.out.println(choice);
            if (choice >= 0 && choice <= 4) {
                user.doOperation(choice, bookList);
            } else {
                System.out.println("Typing error! Please try again.");
            }
        }
    }
}
